﻿@using Think9.Models;
@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<form class="layui-form">
    <div class="layui-tab" lay-filter="tabDemo">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="1">待接收</li>
            <li lay-id="2">办理中</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div style="margin: 5px 5px 5px 5px">
                    <div class="layui-inline">
                        <select id="flist1" name="flist1">
                            <option value="">==请选择==</option>
                            @foreach (valueTextEntity item in ((IEnumerable
                  <valueTextEntity>
                      )ViewBag.SelectList).Where(x => x.ClassID == "flow"))
                            {
                             <option value="@item.Value">@item.Text</option>}
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input class="layui-input" placeholder="关键字" id="key1" autocomplete="off">
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-primary" id="search1"><i class="layui-icon layui-icon-search"></i></button>
                    </div>
                </div>
                <table class="layui-hide" id="tableId01" lay-filter="tableFilter"></table>
            </div>
            <div class="layui-tab-item">
                <div style="margin: 5px 5px 5px 5px">
                    <div class="layui-inline">
                        <select id="flist2" name="flist2">
                            <option value="">==请选择==</option>
                            @foreach (valueTextEntity item in ((IEnumerable
                  <valueTextEntity>
                      )ViewBag.SelectList).Where(x => x.ClassID == "flow"))
                            {
                <option value="@item.Value">@item.Text</option>
}
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input class="layui-input" placeholder="关键字" id="key2" autocomplete="off">
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn layui-btn-primary" id="search2"><i class="layui-icon layui-icon-search"></i></button>
                    </div>
                </div>
                <table class="layui-hide" id="tableId02" lay-filter="tableFilter"></table>
            </div>
        </div>
    </div>
</form>
<script>
    layui.use(["form", "element", "exLayer", "exUtils", "table"], function () {
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let table = layui.table;
        let element = layui.element;
        let $ = layui.$;

        form.render();

        element.on('tab(tabDemo)', function (data) {

        });

        let ThisTable01 = table.render({
            elem: "#tableId01",
            url: "/SysFlow/FlowRunList/GetToBeReceivedList?flid=" + $("#flist1").val() + "&key=" + $("#key1").val(),
            limits: [10, 50, 100],
            limit: 10,
            method: "POST",
            page: true,
            toolbar: "#toolbarTpl",
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { title: "", width: 50, templet: "#islock" }
                , { type: "numbers", title: ".NO" }
                , { field: "RuNumber", title: "编号", width: 100, sort: true }
                , { field: "RunName", title: "名称", sort: true }
                , { field: "BeginUser", title: "发起人", width: 100, sort: true }
                , { field: "BeginTime", title: "创建日期", sort: true }
                , { title: "状态", templet: "#RunFlag", width: 100, sort: true }
                , { field: "CurrentPrcsName", title: "流程步骤", templet: "#PrcsList", width: 100, sort: true }
                , { title: "操作", width: 120, align: "center", fixed: "right", templet: "#operation_Tpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        let ThisTable02 = table.render({
            elem: "#tableId02",
            url: "/SysFlow/FlowRunList/GetInProcessList",
            limits: [10, 50, 100],
            limit: 10,
            method: "POST",
            page: true,
            toolbar: "#toolbarTp2",
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { title: "", width: 50, templet: "#islock" }
                , { type: "numbers", title: ".NO" }
                , { field: "RuNumber", title: "编号", width: 100, sort: true }
                , { field: "RunName", title: "名称", sort: true }
                , { field: "BeginUser", title: "发起人", width: 100, sort: true }
                , { field: "BeginTime", title: "创建日期", sort: true }
                , { title: "状态", templet: "#RunFlag", width: 100, sort: true }
                , { field: "CurrentPrcsName", title: "流程步骤", templet: "#PrcsList", width: 100, sort: true }
                , { title: "操作", width: 120, align: "center", fixed: "right", templet: "#operation_Tpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "detail":
                    //select弹出页面选择 pdf直接打开pdf文件 wwwroot|Report文件夹中可设计样式
                    detail(data.listid, data.FlowId, 'select');
                    break;
                case "edit1":
                    edit01(data.listid, data.FlowId, data.RunName);
                    break;
                case "prcsList":
                    prcsList(data.listid, data.FlowId);
                    break;
            }
        });

        function edit01(id, flowid, RunName) {
            exUtils.ajax("/SysFlow/FlowRunList/BeforeWorkHand", "post", { fwid: flowid, listid: id }, true).done(function (response) {
                exLayer.open(RunName + "-工作办理", "/" + flowid.replace(/fw_/, "") + "/Form?listid=" + id + "&pid=" + response.extra + "&type=edit", '100%', '100%', '0px', '0px', null, null);
            }).fail(function (error) {
                console.log(error);
            });
        }

        function detail(id, fwid, tyep) {
            if (tyep == 'select') {
                layer.open({
                    type: 2,
                    title: "查看数据",
                    shade: 0.5,
                    area: ['380px', '150px'],
                    anim: 2,
                    content: "/" + fwid.replace(/fw_/, "") + "/Detail?listid=" + id + ""
                });
            }
            if (tyep == 'pdf') {
                layer.open({
                    type: 2,
                    title: "查看数据",
                    shade: 0.5,
                    area: ['100%', '100%'],
                    anim: 2,
                    content: "/Com/RDLCReport/ExportPdf?listid=" + id + "&fwid=" + fwid
                });
            }
        }

        function prcsList(id, fwid) {
            exLayer.open('记录查看', '/SysFlow/FlowRunList/RecordList?listid=' + id + "&fwid=" + fwid, '100%', '100%', '0px', '0px', null, null);
        }

        $('#search1').on('click', function () {
            ThisTable01.reload({
                where: { flid: $("#flist1").val(), key: $("#key1").val() },
                page: { curr: 1 }
            });
            return false;
        });

        $('#search2').on('click', function () {
            ThisTable02.reload({
                where: { flid: $("#flist2").val(), key: $("#key2").val() },
                page: { curr: 1 }
            });
            return false;
        });

    });
</script>
<!-- 行工具栏模板 -->
<script type='text/html' id='islock'>
    {{#  if(d.isLock == '1'){ }}
    <i class='fa fa-lock'></i>
    {{#  }else{ }}
    <i class='fa fa-unlock'></i>
    {{#  } }}
</script>
<script type='text/html' id='RunFlag'>
    {{#  if(d.RunFlag == '1'){ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">待接收</span>
    {{#  } }}
    {{#  if(d.RunFlag == '2'){ }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">办理中</span>
    {{#  } }}
    {{#  if(d.RunFlag == '3'){ }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">已结束</span>
    {{#  } }}
</script>
<script type='text/html' id='PrcsList'>
    <a class='layui-btn-rimary layui-btn-sm' href='javascript:;' lay-event='prcsList' id='prcsList'><i class='fa fa-search-minus'></i>{{d.CurrentPrcsName}}</a>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operation_Tpl">
    <a class='layui-btn layui-btn-normal layui-btn-xs' lay-event="detail" id="detail">查看</a>
    <a class='layui-btn layui-btn-normal layui-btn-xs' href='javascript:;' lay-event='edit1' id='edit'>办理</a>
</script>